﻿namespace UnityEditor
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using UnityEngine;

    internal static class EditorAssemblies
    {
        [CompilerGenerated]
        private static Func<Assembly, IEnumerable<System.Type>> <>f__am$cache1;

        private static void RunClassConstructors()
        {
            IEnumerator<System.Type> enumerator = loadedTypes.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    System.Type current = enumerator.Current;
                    if (current.IsDefined(typeof(InitializeOnLoadAttribute), false))
                    {
                        try
                        {
                            RuntimeHelpers.RunClassConstructor(current.TypeHandle);
                            continue;
                        }
                        catch (TypeInitializationException exception)
                        {
                            Debug.LogError(exception.InnerException);
                            continue;
                        }
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
        }

        private static void SetLoadedEditorAssemblies(Assembly[] assemblies)
        {
            loadedAssemblies = assemblies;
            RunClassConstructors();
        }

        internal static IEnumerable<System.Type> SubclassesOf(System.Type parent)
        {
            <SubclassesOf>c__AnonStoreyA ya = new <SubclassesOf>c__AnonStoreyA {
                parent = parent
            };
            return Enumerable.Where<System.Type>(loadedTypes, new Func<System.Type, bool>(ya.<>m__7));
        }

        internal static Assembly[] loadedAssemblies
        {
            [CompilerGenerated]
            get
            {
                return <loadedAssemblies>k__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                <loadedAssemblies>k__BackingField = value;
            }
        }

        internal static IEnumerable<System.Type> loadedTypes
        {
            get
            {
                if (<>f__am$cache1 == null)
                {
                    <>f__am$cache1 = assembly => AssemblyHelper.GetTypesFromAssembly(assembly);
                }
                return Enumerable.SelectMany<Assembly, System.Type>(loadedAssemblies, <>f__am$cache1);
            }
        }

        [CompilerGenerated]
        private sealed class <SubclassesOf>c__AnonStoreyA
        {
            internal System.Type parent;

            internal bool <>m__7(System.Type klass)
            {
                return klass.IsSubclassOf(this.parent);
            }
        }
    }
}

